package com.guo.rabbitmq.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author gonghuaiguo
 */
@Slf4j
@Component
public class SpringRabbitListener {

    @RabbitListener(queues = "simple.queue")
    public void listenSimpleQueueMessage(String msg) throws InterruptedException {
        log.info("spring 消费者 接收到消息：【" + msg + "】");
        throw new RuntimeException("故意的");
    }

    @RabbitListener(queues = "work.queue")
    public void listenWorkQueueMessage(String msg) throws InterruptedException {
        System.out.println("spring 消费者1 接收到消息：【" + msg + "】");
        Thread.sleep(200);
    }

    @RabbitListener(queues = "work.queue")
    public void listenWorkQueueMessage2(String msg) throws InterruptedException {
        System.out.println("spring 消费者2 接收到消息：【" + msg + "】");
        Thread.sleep(20);
    }

    @RabbitListener(queues = "fanout.queue1")
    public void fanoutQueueMessage1(String msg){
        System.out.println("消费者1 接受到消息：【" +msg+"】");
    }

    @RabbitListener(queues = "fanout.queue2")
    public void fanoutQueueMessage2(String msg){
        System.out.println("消费者2 接受到消息：【" +msg+"】");
    }

    @RabbitListener(queues = "direct.queue1")
    public void listenDirectQueue1(String msg) {
        System.out.println("消费者1接收到direct.queue1的消息：【" + msg + "】");
    }

    @RabbitListener(queues = "direct.queue2")
    public void listenDirectQueue2(String msg) {
        System.out.println("消费者2接收到direct.queue2的消息：【" + msg + "】");
    }

    @RabbitListener(queues = "topic.queue1")
    public void listenTopicQueue1(String msg){
        System.out.println("消费者1接收到topic.queue1的消息：【" + msg + "】");
    }

    @RabbitListener(queues = "topic.queue2")
    public void listenTopicQueue2(String msg){
        System.out.println("消费者2接收到topic.queue2的消息：【" + msg + "】");
    }

    @RabbitListener(queues = "object.queue")
    public void listenSimpleQueueMessage(Map<String, Object> msg) throws InterruptedException {
        System.out.println("消费者接收到object.queue消息：【" + msg + "】");
    }


}
